
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;

namespace HousingInfo.Library
{ 
	public partial class OptionBO : Csla.BusinessBase<OptionBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in OptionBO
			//AuthorizationRules.AllowRead(OptionIDProperty, "OptionBOReadGroup");
			//AuthorizationRules.AllowRead(OptionNameProperty, "OptionBOReadGroup");
			//AuthorizationRules.AllowRead(OptionValueProperty, "OptionBOReadGroup");

			//AuthorizationRules.AllowWrite(OptionNameProperty, "OptionBOWriteGroup");
			//AuthorizationRules.AllowWrite(OptionValueProperty, "OptionBOWriteGroup");
		}

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of OptionBO
			//AuthorizationRules.AllowCreate(typeof(OptionBO), "OptionBOCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(OptionBO), "OptionBOEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(OptionBO), "OptionBODeleteGroup"));
		}
		#endregion //Authorization Rules
		private void AssignParentKey(HousingInfo.DataLinQ.Option data)
		{
			 //data.ParentId = ReadProperty<ParentBO>(ParentBOProperty).Id;
        }
        #region Trang Quan Ly Vi Tri Quang Cao

        #region Ham Lay option so luong quang cao
        //ham duoc goi
        public static OptionBO GetNameOptionBO(string optionName)
        {
            return DataPortal.Fetch<OptionBO>(new FilterCriteria_GetOptionByName(optionName));
        }
        //xu ly truy cap du lieu
        private void DataPortal_Fetch(FilterCriteria_GetOptionByName criteria)
        {
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                var data = mgr.DataContext.Options
                        .Single(r => r.OptionName == criteria.option_name);

                OnMemberLoading(data);
                LoadProperty<int>(OptionIDProperty, data.OptionID);
                LoadProperty<string>(OptionNameProperty, data.OptionName);
                LoadProperty<string>(OptionValueProperty, data.OptionValue);
                //OnMemberLoaded();

                ValidationRules.CheckRules();
            }//using

            //OnFetched();
        }
        //khai bao tham so su dung
        private class FilterCriteria_GetOptionByName
        {
            public string option_name;
            public FilterCriteria_GetOptionByName(string op_name)
            {
                this.option_name = op_name;
            }
        }
        #endregion

        #endregion

    }
}
